home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / shells / scsh-0.4 / scsh-0 / scsh-0.4.2 / scsh / sunos / time_dep1.c < prev    next >
C/C++ Source or Header  |  1995-10-13  |  1KB  |  39 lines

  1. /* OS-dependent support for fine-grained timer.
  2. ** Copyright (c) 1995 by Olin Shivers.
  3. **
  4. ** We return the current time in seconds and sub-second "ticks" where the 
  5. ** number of ticks/second is OS dependent (and is defined in time_dep.scm).
  6. ** This definition works on any BSD Unix with the gettimeofday() 
  7. ** microsecond-resolution timer.
  8. */
  9.  
  10. #include <errno.h>
  11. #include <sys/time.h>
  12. #include "scheme48.h"
  13. #include "../time1.h"
  14.  
  15. /* Sux because it's dependent on 32-bitness. */
  16. #define hi8(i)  (((i)>>24) & 0xff)
  17. #define lo24(i) ((i) & 0xffffff)
  18. #define comp8_24(hi, lo) (((hi)<<24) + (lo))
  19.  
  20. scheme_value time_plus_ticks(int *hi_secs, int *lo_secs,
  21.                  int *hi_ticks, int *lo_ticks)
  22. {
  23.     struct timeval t;
  24.     struct timezone tz;
  25.  
  26.     if( gettimeofday(&t, &tz) ) return ENTER_FIXNUM(errno);
  27.  
  28.     {   long int secs  = t.tv_sec;
  29.     long int ticks = t.tv_usec;
  30.      
  31.         *hi_secs  = hi8(secs);
  32.         *lo_secs  = lo24(secs);
  33.         *hi_ticks = hi8(ticks);
  34.         *lo_ticks = lo24(ticks);
  35.         }
  36.  
  37.     return SCHFALSE;
  38.     }
  39.